<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>KAR Events</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/head.inc");  ?>

</head>

<body>

<!--initial body width and height set up  -->
<div id="bodywidth">

<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/header.inc");  ?>
<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/leftmenu.inc");  ?>


<!--wide2column enter here -->
<div id="wide2column">
<CENTER><H2>Pets at Events!</H2>
</CENTER><BR CLEAR=ALL>


<!-- Adding file for event scheduler -->

<?php


include($_SERVER['DOCUMENT_ROOT'] ."/includes/db.php");

				// Connect to the database server
dbConnect('kar_web1');   	// Use function in db.php to connect


if (empty($eventID)){	// if an ID didn't get passed in
	$eventID=2;
} //  end if

// Get set up to put events  into drop-down list for SELECT in Form
//  This is to present the user a drop down of possible events to schedule for
//  Only displays events that have not passed.
$resultEvent = @mysql_query("SELECT * FROM events 
			     WHERE eventID= $eventID");

if (!$resultEvent) {
  echo("<p>Error performing query: " . mysql_error() . "</p>");
  exit();
  }  // end if



while ($row = mysql_fetch_array($resultEvent)) {
		$location_query = @mysql_query("SELECT *
									FROM locations
									WHERE location_id = ".$row["location_id"]) or
								die("Error getting event location. ".mysql_error());
		$location_fetch = mysql_fetch_array($location_query);
		$eventName = $location_fetch["Title"];
		
		if(($row["location_id"] == 3)||($row["location_id"] == 4)) {
			$eventName = substr($eventName, 0, 17);
		}
		
		if($row["eventName"] != "") {
			$eventName = $row["eventName"]. " at ".$eventName;
		} else {
			$eventName = $eventName." adoption event";
		}
// Setting up BeginTime & EndTime to print in Tips section 
	$BTime =  $row["eventBeginTime"];
	list($Bhour, $Bmin, $Bsec) = explode(":", $BTime);
	$BeginTime = date("g:i a", mktime($Bhour, $Bmin));
	$ETime =  $row["eventEndTime"];
	list($Ehour, $Emin, $Esec) = explode(":", $ETime);
	$EndTime = date("g:i a", mktime($Ehour, $Emin));

// eventID is the primary key for the Events Table and will be stored with the scheduled  pet record
	$event = $row["eventID"];
//  eventDate is stored in format yyyy-mm-dd
	list($year, $month, $day)  = explode("-", $row["eventDate"]);
	$eventDate = date("l, F j, Y", mktime(0,0,0,$month, $day,$year));
// SAMPLE OF USAGE $showdate = date("l, F j, Y", mktime(0,0,0,$month, $day,$year));
	$option_blockEvent .= "<OPTION value=\"$event\">$eventName - $eventDate</OPTION>";
	$eventList .= $eventName ." on ". $eventDate." from ". $BeginTime . " to " . $EndTime . "<br>";
}  // end while


$event=strtotime("$month/$day/$year");
$today=strtotime("now");

		if (time() < mktime($Ehour,$Emin,0,$month,$day,$year)) { 
		echo ("These pets are scheduled to be at the:<br>"); }
		else {
		echo ("You missed it!   These pets were at the"); }
	 


?>

<CENTER>
<font size="+1"><b><?=$eventName?><br>
on <?=$eventDate?>,<br>

<?
	if (time() < mktime($Ehour,$Emin,0,$month,$day,$year)) {
		echo ("an event that runs from<br>");  }
	else {
		echo ("an event that ran from<br>"); }
?>

 <?=$BeginTime?> to <?=$EndTime?>
</b></font> 
</CENTER>
<br><br>

<?

// 7/31/07 deleted part of query that was only pulling animals if event had not passed.

$result = @mysql_query("SELECT * FROM eventPets, dogs, cats
			WHERE (eventPets.tagNum=cats.tagNum
			OR eventPets.tagNum=dogs.tagNum)
			AND (cats.pet_status = 'v' OR dogs.pet_status = 'v')
			AND eventID = $eventID 
			ORDER BY eventDate, arrive_time ASC");

$num_rows = mysql_num_rows($result);

$num_columns=3;				// how many columns we want those split between

if (!$result) {
  echo("<p>Error performing query: " . mysql_error() . "</p>");
  exit();
}  // end if

if ($num_rows <> 0) {

	    echo ("Click on the animal's picture to get their full description.<br><br>");

	$row = mysql_fetch_array($result) ;

	if ($row) 				 // if there were any scheduled pets
	   {                    
	    $new_date = $row["eventDate"];    // get date for first check
	    //  Get YYYY-MM-DD
	    list($year, $month, $day) = explode("-", $new_date); 
	    $showMonth = date("l, F j, Y", mktime(0,0,0,$month, $day,$year));

	    echo("<CENTER><TABLE  cellpadding=\"10\">");
  	   $count=0;   //  track how many in row on table
	    }  // end if

	while ( $row )  {			// while there is data
		$id = $row["tagNum"];
		$name =  $row["tagNum"];
		$date = $row["eventDate"];
		$a_time = $row["arrive_time"];
		$b_time = $row["depart_time"];

/*		if ($row["pet_type"] == 'c') {
			$path = "http://kalamazooanimalrescue.org/images/cats/thmbnail/";
		} else {
			$path = "http://kalamazooanimalrescue.org/images/dogs/thmbnail/";
		}  // end if
*/

	if  ($new_date == $date) {

		$count=$count+1;
		if ( ($count%$num_columns) == 1):		// if it's the first slot in the row, start the row
			echo ("<TR><TD>");
		else:
			echo ("<TD>");
		endif;

		echo("<CENTER><a href='../pets2.php?displaypet=$id'>");
		echo("<img SRC=\"". $path . $row["thumb"] . "\" border=2 align=\"middle\"  width=\"75\" height=\"75\" alt=\"$name\"></a> <br>" );
		echo ($name . "<br> " . $a_time ." - ".$b_time . "</CENTER><br><HR><br>");
	 }   else  {
		echo("<HR>");
		$new_date = $date;	//  change to next date
		list($year, $month, $day) = explode("-", $new_date);
		$showMonth = date("l, F j, Y", mktime(0,0,0,$month, $day,$year));
		echo ("<CENTER><b>".$showMonth . "</b></CENTER><br>");
		echo("<a href='../pets2.php?displaypet=$id'>");
		echo("<img SRC=\"". $path . $row["thumb"] . "\" align=\"middle\" width=\"75\" height=\"75\" alt=\"$name\"></a> " );
		echo ($name . "    " . $a_time ." - ".$b_time . "<br><br>");
                     }	// end if 

		if ( ($count%$num_columns) == 0):	// if it's the last slot in the row, end the row
			echo ("</TD></TR>");
		else:
			echo ("</TD>");
		endif;
	$row = mysql_fetch_array($result) ;     // get next row of stuff

	}  // end while

}
else {
	echo("<br><br><font color=red size=+1><b>Oops!&nbsp;&nbsp;There are no pets on the schedule right now but please check 	back frequently as they will be scheduled closer to the event.</b></font><br><br>");

}


//  We need to complete and close the last table.
$leftover = ($count % $num_columns);	// number of animals to display MOD number of columns

if ($leftover <> 0):		//  did we have enough pets to finish out the table?
	$fill_in = ($num_columns - $leftover); 	//  fill this many cells with nothing
	for ($i=1; $i <= $fill_in; $i++) {
		echo("<TD>&nbsp;</TD>");
		if ($i == $fill_in)		//  We're on the last cell of the row
			echo("</TR>");
	}	// end for
endif;
echo ("</TABLE></CENTER><br>");


	    echo ("<a href=\"./events.php\">Return</a> to the Events page --<br><br>");
?>
  </div>

<!-- clearit allows the footer to wrap back to left in Foxfire -->
<div class="clearit"></div>

<?php include($_SERVER['DOCUMENT_ROOT'] ."/includes/footer.inc");  ?>

</div>
</body>
</html>
